package com.starter.canal.test1.consumer;

import com.alibaba.fastjson2.JSON;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.starter.canal.test1.model.User;
import com.utopa.canal.client.annotation.CanalListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 类的描述
 *
 * @author Administrator
 * @date 2022-08-18
 */
@Slf4j
@Component
public class CanalConsumer {
    @CanalListener(databaseName = "test", tableName = "t_user")
    public void consumerUser(User user, CanalEntry.EventType eventType) {
        log.info("操作类型={}，操作数据user={}", eventType.name(), JSON.toJSONString(user));
        switch (eventType) {
            case INSERT:
                log.info("=========执行新增逻辑...");
                //userRepository.insert(user);
                break;
            case UPDATE:
                log.info("=========执行修改逻辑...");
                //userRepository.update(user);
                break;
            case DELETE:
                log.info("=========执行删除逻辑...");
                //userRepository.delete(user);
                break;
            default:
                log.warn("=========操作类型不匹配...");
                break;
        }
    }
}
